package org.restorator.di;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;

/**
 * @author Snisar Bogdan.
 */
public class Ref {

    public Ref(String key, Class<?> clazz) {
        this.key = key;
        this.clazz = clazz;
    }


    final String key;

    /**
     * Target to injection. Refs that depended from this ref.
     */
    List<Ref> parentRef;

    /**
     * Injections. Refs that mast be inject to this ref,
     * as this ref depended from childes refs.
     */
    List<Ref> childRef;

    /**
     * Class reference
     */
    final Class<?> clazz;

    /**
     * Methods to injection and other
     */
    Method[] methods;

    /**
     * Args
     */
    Object[][] methodArgs;

    /**
     * Constructor, or null is default
     */
    Constructor<?> constructor;
    /**
     * Args
     */
    Object[] constructorArgs;

    /**
     * Or factory method
     */
    Method factory;

    /**
     * Method args or null if with out
     */
    Object[] factoryArgs;

    /**
     * Singleton?
     */
    boolean single;

    /*Generated by IDEA */

    @Override
    public int hashCode() {
        return 37 * (17 + key.hashCode() + clazz.hashCode());
    }

    @Override
    public String toString() {
        return "<[ This is " + super.toString() + ". Key: " + key +
                ", class: " + clazz + ", constructor: " + constructor + ", methods" + Arrays.toString(methods);
    }

    @Override
    public boolean equals(Object obj) {
        return obj != null
                && (obj == this
                || obj instanceof Ref
                && this.key.equals(((Ref) obj).key));
    }
}
